# 封装请求
import requests


class RequestsHandler:

    def __init__(self):
        # 实例化session
        self.session = requests.Session()

    def visit(self, method, url, headers=None, data=None, json=None, **kwargs):

        res = self.session.request(method, url, headers=headers, data=data, json=json, **kwargs)
        try:
            return res
        except ValueError as e:
            raise e

    def close_session(self):
        self.session.close()
